package com.lh.java.basic.threadlocal;

public class TestThreadLocalOutOfMem {
	public static void main(String[] args) {
		TestThreadLocalOutOfMem a = new TestThreadLocalOutOfMem();
		a.start();
	}
	ThreadLocal<Content> tl = new ThreadLocal<Content>();

	void start() {
		System.out.println("begin");
		Content content = tl.get();
		if (content == null) {
			content = new Content();
			tl.set(content);
		}
		System.out.println("try to release content data");
		 tl.set(null);//@1
//		 tl.remove();//@2
//		tl = null;// @3
		content = null;// @4
		System.out.println("request gc");
		System.gc();
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			// TODO Auto-gene/rated catch block
			e.printStackTrace();
		}
		System.out.println("end");
	}
}

class Content {
	byte data[] = new byte[1024 * 1024 * 10];

	protected void finalize() {
		System.out.println("I am released");
	}
}
